package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.RequestCityPromotionEmailHandler;
import com.cungmua.app.model.request.CityPromotionEmailRequest;
import com.cungmua.app.model.response.CityPromotionEmailResponse;
import com.cungmua.app.net.CungMuaAPI;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 7/26/14.
 */
public class RequestCityPromotionEmailTask extends AuthenticatedTask<CityPromotionEmailRequest, Void, CityPromotionEmailResponse> {
    private final Context context;
    private RequestCityPromotionEmailHandler handler;

    public RequestCityPromotionEmailTask(Context context, RequestCityPromotionEmailHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected CityPromotionEmailResponse doInBackground() throws RetrofitError {
        CityPromotionEmailRequest request=params[0];

        return CungMuaAPI.getService().getListCityPromotionEmails(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(CityPromotionEmailResponse cityPromotionEmailResponse) {
        handler.onListCityPromotionEmails(cityPromotionEmailResponse);
    }
}
